home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 2.5 KB | 95 lines | [TEXT/ttxt] |
- --<<<-
- -- Filename:
- -- traveler.sx
-
- -- Other Files Required:
- -- None
-
- -- Purpose:
- -- Class definition for the Traveler class.
-
- -- Specialized Classes:
- -- Traveler
-
- -- Instructions to User:
- -- Defines the Traveler class, which supports simple interpolation to any arbitrary
- -- destination. The Traveler has a clock, which tickles an interpolator when the
- -- Traveler is traveling.
- --
- -- Protocol:
- -- travel self destination duration -- interpolate to location <destination> in duration ticks.
- -- leave -- interpolate using present destination and duration
-
- -- Author:
- -- Steve Mayer
-
- -- Class Traveler is an object which can travel to destination points
- -- in a specified duration. Uses an Interpolator to do the traveling.
-
- in module Autofinder
-
- class Traveler ()
- instance variables
- travelClock
- travelInterpolator
- destination
- duration
- ready
- end
-
- method init self {class Traveler} #rest args #key travelClock: (new Clock scale:12) \
- travelInterpolator: (undefined) destination: duration: ->
- (
- apply nextMethod self args
- self.travelClock := travelClock
- self.travelInterpolator := travelInterpolator
- self.destination := destination
- self.duration := duration
- self.ready := false
- return self
- )
-
- method arrive self {class Traveler} ->
- (
- self.travelClock.rate := 0
- self.ready := false
- self.travelInterpolator.space := undefined
- self.travelInterpolator := undefined
- )
-
- method travelPrepare self {class Traveler} ->
- (
- self.travelInterpolator := new Interpolator space:self.presentedBy clock:self.travelClock
- append self.travelInterpolator self
- self.ready := true
- )
-
- method leave self {class Traveler} ->
- (
- if (not self.ready) do travelPrepare self
-
- -- Calculate destination time and set the destination of the Interpolator.
- local destinationTime := self.travelClock.time + self.duration
- setDestination self.travelInterpolator self.destination destinationTime
-
- -- Add a callback for the end of the trip, and start traveling.
- -- remove any previous TimeCallbacks
- local cb := chooseAll self.travelClock.callBacks (tcb dummy -> \
- isAKindOf tcb TimeCallBack) undefined
- forEach cb (item arg -> cancel item) undefined
-
- -- Add a callback for the end of the trip, and start traveling.
- addTimeCallback self.travelClock arrive self #() destinationTime true
- self.travelClock.rate := 1
- )
-
- method travel self {class Traveler} destination duration ->
- (
- if (not self.ready) do travelPrepare self
- self.destination := destination
- self.duration := duration
- leave self
- )
- -->>>
- "Compiled traveler.sx"
-